<?php
/*
 * [佳喜网络!] (C)2008-2009 JiaXi Inc.
 * $Id: include.php 2008-8-13 19:28:02 pepsi.zh $
 * -------------------------------------------
 * 网址：www.he88.cn
 * -------------------------------------------
 * 这是一个共享软件，遵循我们公司的共享协议。
*/
define('UNINCLUDELIMIT',true);
$outvar = array();
include_once('include/include.php');
$outvar[csslist][] = $outvar[css_url].'register.css';
$outvar[jslist][] = DEFAULT_JS_URL.'user_register.js';

if (isset($_SESSION[userName])){
	switch ($_SESSION[registerstep]){
		case 2 : 
			header("location:register_step2.php");
			break;
		default:
			header("location:register_step3.php");
			break;
	}
}
if ($_POST){
	$_POST = acrossTrim($_POST);
	$flag = true;
	$_POST[zusername] = strtolower($_POST[zusername]);
	$strlong = strlen($_POST[zusername]);
	if ($strlong < 3 || $strlong >30){
		$flag = false;
		$error[zusername_error] = '用户名字符在3-15之间';
	}else {
		$post[zusername] = $_POST[zusername];
	}
	if (empty($_POST[zpassword])){
		$flag = false;
		$error[zpassword_error] = '密码不能为空';
	}else {
		if ($_POST[zpassword] != $_POST[repeat_one]){
			$flag = false;
			$error[repeat_one_error] = '两次密码输入不一致';
		}else{
			$post[zpassword] = md5($_POST[zpassword]);
		}
	}
	if (!preg_match(PREG_EMAIL,$_POST[zemail])){
		$flag = false;
		$error[zemail_error] = '您输入的E-mail格式不正确';
	}else{
		$post[zemail] = $_POST[zemail];
	}
	if (!stristr($_POST[imgcode],$_SESSION[s_verify])){
		$flag = false;
		$error[imgcode_error] = '验证码输入错误'.$_SESSION[s_verify];
	}
	if ($flag){
		c_create::createClass('user');
		$user = new user();
		if ($user->checkExists($post[zusername]) > 0){
			$flag = false;
			$error[zusername_error] = '您输入的用户名已经存在';
		}
	}
	if ($flag){
		$post[zfullname] = $_POST[zfullname];
		$post[zregdate] = time();
		$post[zregip] = $_SERVER[REMOTE_ADDR];
		$post[zlogindate] = $post[zregdate];
		$post[zloginip] = $post[zregip];
		global $dbconn,$dbtable;
		if ($dbconn->addData($post,$dbtable->user)){
			c_create::createClass('user');
			$user = new user();
			$user->userLogin($post[zusername],$_POST[zpassword]);
			$_SESSION[registerstep] = 2;
			$_SESSION[showtip] = '注册成功！';
			header("location:register_step2.php");
			exit;
		}else {
			$_SESSION[showtip] = '提交失败，请检查错误';
		}
	}
	$outvar = addArray($outvar,$_POST);
	$outvar = addArray($outvar,$error);
}

////// xajax部分
//require_once("./include/xajax_common.php");
//$outvar[xajax_javascript] = $xajax->getJavascript(SITE_URL.'plus/xajax/');

outFile('member/register');
?>